import 'dart:convert';

class CommentEntityInner {
  String? id;
  String? mid;
  String? cover;
  String ?uid;
  String ?username;
  String? replyName;
  String? replyContent;
  String? avatar;
  String? pid;
  String? replyUid;
  String? replyId;
  int? level;
  String? sort;
  String? content;
  String? count;
  List<CommentEntityInner>? childrenComments;
  int? createDate;
  bool? isAgree;
  String? twoNums;

  CommentEntityInner({
    required this.id,
    required this.mid,
    required this.cover,
    required this.uid,
    required this.username,
    this.replyName,
    this.replyContent,
    required this.avatar,
    required this.pid,
    required this.replyUid,
    required this.replyId,
    required this.level,
    this.sort,
    required this.content,
    required this.count,
    this.childrenComments,
    required this.createDate,
    this.isAgree,
    required this.twoNums,
  });

  factory CommentEntityInner.fromJson(Map<String, dynamic> json) {
    return CommentEntityInner(
      id: json['id'],
      mid: json['mid'],
      cover: json['cover'],
      uid: json['uid'],
      username: json['username'],
      replyName: json['replyName'],
      replyContent: json['replyContent'],
      avatar: json['avatar'],
      pid: json['pid'],
      replyUid: json['replyUid'],
      replyId: json['replyId'],
      level: json['level'],
      sort: json['sort'],
      content: json['content'],
      count: json['count'],
      childrenComments: json['childrenComments'] != null
          ? (json['childrenComments'] as List<dynamic>)
              .map((e) => CommentEntityInner.fromJson(e))
              .toList()
          : null,
      createDate: json['createDate'],
      isAgree: json['isAgree'],
      twoNums: json['twoNums'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'mid': mid,
      'cover': cover,
      'uid': uid,
      'username': username,
      'replyName': replyName,
      'replyContent': replyContent,
      'avatar': avatar,
      'pid': pid,
      'replyUid': replyUid,
      'replyId': replyId,
      'level': level,
      'sort': sort,
      'content': content,
      'count': count,
      'childrenComments': childrenComments?.map((e) => e.toJson()).toList(),
      'createDate': createDate,
      'isAgree': isAgree,
      'twoNums': twoNums,
    };
  }
}

class CommentEntityList {
  List<CommentEntityInner> comments;

  CommentEntityList({required this.comments});

  factory CommentEntityList.fromJson(List<dynamic> jsonString) {

    return CommentEntityList(
      comments: jsonString.map((json) => CommentEntityInner.fromJson(json)).toList(),
    );
  }

  String toJson() {
    return json.encode(comments.map((comment) => comment.toJson()).toList());
  }
}
